class Solution(object):
    def containsNearbyDuplicate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: bool
        """
        numscount = dict()
        for i in range(0 , len(nums)):
            v = nums[i]
            if v in numscount.keys():
                if k>=(i - numscount[v]):
                    return True
            numscount[v]=i
        return False

s = Solution()
s.containsNearbyDuplicate([1,2,3,1] , 3)
            
